using System.Threading;

namespace Catastrophe.Common.ThreadLock
{
	internal sealed class Singleton
	{
		private static object m_lock = new object();

		private static Singleton SValue = null;

		public static Singleton GetSingleton()
		{
			if (Singleton.SValue != null)
			{
				return Singleton.SValue;
			}
			Monitor.Enter(Singleton.m_lock);
			if (Singleton.SValue == null)
			{
				Singleton value = new Singleton();
				Volatile.Write(ref Singleton.SValue, value);
				Singleton.SValue = new Singleton();
			}
			Monitor.Exit(Singleton.m_lock);
			return Singleton.SValue;
		}
	}
}
